// 全选
function checkBox(name,checked){
    //全选开始
    $("input[name='"+name+"']").prop("checked", checked);
}
// 批量删除
function optDelete() {
    // 首先获取所有选中的id集合
    var check = $(".checked_detect:checked");
    // 定义一个存放id集合的数组
    var ids = new Array();
    for (var i=0; i < check.length; i++) {
        ids[i] = $(check[i]).attr("value");
    }
    // 判断是否选择了一个元素
    if (ids.length == 0) {
        new $.zui.Messager('提示消息：' + "请至少选择一个", {
            icon: 'exclamation-sign',
            type: 'danger',
            time: 2000
        }).show();
        return;
    }
    // 批量删除确认
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要删除选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type : "POST",
                    cache : false,
                    url : "/admin/processInstance/deleteBatch",
                    data : {ids :ids},
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType:"json",
                    success : function (result) {
                        if (result.errorCode == 'y') {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'success',
                                time: 2000
                            }).show();
                            setTimeout("location.reload()", 1000);
                        } else {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'danger',
                                time: 2000
                            }).show();
                        }
                    },error : function(result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 挂起、激活
function hangActiveTraceNode(state, id) {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要挂起/激活选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type: "GET",
                    cache: false,
                    url: "/admin/processInstance/update/" + state + "/" +id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        if (result.errorCode == 'y') {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'success',
                                time: 2000
                            }).show();
                            setTimeout("location.reload()", 1000);
                        } else {
                            new $.zui.Messager('提示消息：' + result.errorText, {
                                icon: 'exclamation-sign',
                                type: 'danger',
                                time: 2000
                            }).show();
                        }
                    }, error: function (result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 查看流程图
function viewTraceNode(id) {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要查看选择的数据吗？",
        callback: function (result) {
            if (result) {
                $.ajax({
                    type: "GET",
                    cache: false,
                    url: "/admin/processInstance/trace/" + id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        $("#ImageTracePic").empty();
                        //将图片的Base64编码设置给src
                        $("#ImageTracePic").attr("src","data:image/png;base64,"+result);
                        $('#ImgTraceModal').modal({
                            keyboard : false,
                            show     : true
                        });
                    }, error: function (result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}
// 根据流程实例ID查看对应的流程变量数据
function viewVariablesNode(id) {
    bootbox.confirm({
        title: "操作提示",
        size: "small",
        message: "你确定要查看选择的数据吗？",
        callback: function (result) {
            if (result) {
                var variables = null;
                $.ajax({
                    type: "GET",
                    cache: false,
                    url: "/admin/processInstance/findProcessVariables/" + id,
                    contentType: "application/x-www-form-urlencoded;charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        /*console.log("variables: " + result.variables);*/
                        // JSON.parse(jsonstr); //可以将json字符串转换成json对象
                        // JSON.stringify(jsonobj); //可以将json对象转换成json对符串
                        variables = JSON.stringify(result.variables);
                        /*console.log("variables: " + variables);*/
                        $("#processVariables").empty();
                        $("#processVariables").html(variables);
                        // 显示模态框
                        $('#processVariablesModal').modal({
                            keyboard : false,
                            show     : true
                        });
                    }, error: function (result) {
                        new $.zui.Messager('提示消息：' + result.errorText, {
                            icon: 'exclamation-sign',
                            type: 'danger',
                            time: 2000
                        }).show();
                    }
                });
            }
        }
    });
}